package com.itheima.chapter04.arraylist;

import com.itheima.domian.Student;

import java.util.ArrayList;
import java.util.Scanner;

/*
    键盘录入学生信息到集合
 */
public class demo6 {
    public static void main(String[] args) {
        ArrayList<Student> array =new ArrayList<>();
        Student s1 = getStudent();
        Student s2 = getStudent();
        Student s3 = getStudent();
        array.add(s1);
        array.add(s2);
        array.add(s3);
        for (int i = 0; i < array.size(); i++) {
            Student s = array.get(i);
            System.out.println(s);
            System.out.println(s.getName()+"、、、"+s.getAge());
        }
    }
    public static Student getStudent(){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生姓名：");
        String name = sc.next();
        System.out.println("请输入学生年龄：");
        int age = sc.nextInt();
        Student s = new Student(name,age);
        return s;
    }
}
